package jsyf.oa.dao.device;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.oa.entity.device.BrandBankEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by y on 2018/7/6.
 */
@Repository
public class BrandBankDao extends BaseDao {
    public BrandBankDao() {
        super.iBaseEntity = new BrandBankEntity();
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {

        return JSON.toJavaObject(json, BrandBankEntity.class);
    }

    public List<JSONObject> getBankList() {
        StringBuffer sql = new StringBuffer();
        sql.append(" SELECT\n" +
                "\tt_dvc_brand_bank.ID as id,\n" +
                "  t_dvc_brand.BRAND_NAME as brandName,\n" +
                "  t_dvc_brand_bank.BRAND_ID as brandId,\n" +
                "  t_dvc_brand_bank.BANK_NAME as bankName,\n" +
                "  t_dvc_brand_bank.INTERMEDIARY_BANK as intermediaryBank,\n" +
                "  t_dvc_brand_bank.BANK_ACCOUNT as bankAccount\n" +
                "FROM\n" +
                "\tt_dvc_brand_bank LEFT JOIN t_dvc_brand ON t_dvc_brand_bank.BRAND_ID=t_dvc_brand.ID\n" +
                " WHERE t_dvc_brand_bank.DEL_FLAG=0 order by t_dvc_brand.BRAND_NAME");
        return super.queryForJsonList(sql.toString());
    }
    public List<JSONObject> getBankAndAccount(String condition,Object[] params) {
        StringBuffer sql=new StringBuffer();
        sql.append(" SELECT ");
        sql.append(" ID as id,");
        sql.append(" BRAND_ID as brandId,");
        sql.append(" INTERMEDIARY_BANK as intermediaryBank,");
        sql.append(" BANK_ACCOUNT as bankAccount,");
        sql.append(" BANK_NAME as bankName");
        sql.append(" FROM T_DVC_BRAND_BANK WHERE 1=1 ");
        sql.append(condition);
        return super.queryForJsonList(sql.toString(),params);
    }

    public JSONObject getBankAndAccountById(String condition,Object[] params) {
        StringBuffer sql=new StringBuffer();
        sql.append(" SELECT ");
        sql.append(" ID as id,");
        sql.append(" BRAND_ID as brandId,");
        sql.append(" INTERMEDIARY_BANK as intermediaryBank,");
        sql.append(" BANK_ACCOUNT as bankAccount,");
        sql.append(" BANK_NAME as bankName");
        sql.append(" FROM T_DVC_BRAND_BANK WHERE 1=1 ");
        sql.append(condition);
        return super.queryForJsonObject(sql.toString(),params);
    }
}
